04. Installing mod_wsgi
Installing mod_wsgi
When Apache receives a request it has a number of ways it can respond. What you’ve seen thus far is the simplest method of operation, Apache just returns a file requested or the index.html
file if no file is defined within the URL.
But, Apache can do so much more! You’ll now configure Apache to hand-off certain requests to an application handler - mod_wsgi. The first step in this process is to install mod_wsgi: sudo apt-get install libapache2-mod-wsgi
.
You then need to configure Apache to handle requests using the WSGI module. You’ll do this by editing the /etc/apache2/sites-enabled/000-default.conf
file. This file tells Apache how to respond to requests, where to find the files for a particular site and much more. You can read up on everything this file can do within the Apache documentation.
For now, add the following line at the end of the <VirtualHost *:80>
block, right before the closing </VirtualHost>
line: WSGIScriptAlias / /var/www/html/myapp.wsgi
Finally, restart Apache with the sudo apache2ctl restart
command.
You might get a warning saying "Could not reliably determine the server's fully qualified domain name". If you do, don't worry about it. Check out this AskUbuntu thread for a discussion of the cause of this message.